package com.ruoyi.web.controller.code;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Money;
import com.ruoyi.web.service.IMoneyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 贷款申请Controller
 * 
 * @author ruoyi
 * @date 2025-06-04
 */
@RestController
@RequestMapping("/web/money")
public class MoneyController extends BaseController
{
    private IMoneyService moneyService;

    /**
     * 查询贷款申请列表
     */
    @PreAuthorize("@ss.hasPermi('web:money:list')")
    @GetMapping("/list")
    public TableDataInfo list(Money money)
    {
        startPage();
        List<Money> list = moneyService.selectMoneyList(money);
        return getDataTable(list);
    }

    /**
     * 导出贷款申请列表
     */
    @PreAuthorize("@ss.hasPermi('web:money:export')")
    @Log(title = "贷款申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Money money)
    {
        List<Money> list = moneyService.selectMoneyList(money);
        ExcelUtil<Money> util = new ExcelUtil<Money>(Money.class);
        util.exportExcel(response, list, "贷款申请数据");
    }

    /**
     * 获取贷款申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('web:money:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(moneyService.selectMoneyById(id));
    }

    /**
     * 新增贷款申请
     */
    @PreAuthorize("@ss.hasPermi('web:money:add')")
    @Log(title = "贷款申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Money money)
    {
        return toAjax(moneyService.insertMoney(money));
    }

    /**
     * 修改贷款申请
     */
    @PreAuthorize("@ss.hasPermi('web:money:edit')")
    @Log(title = "贷款申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Money money)
    {
        return toAjax(moneyService.updateMoney(money));
    }

    /**
     * 删除贷款申请
     */
    @PreAuthorize("@ss.hasPermi('web:money:remove')")
    @Log(title = "贷款申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(moneyService.deleteMoneyByIds(ids));
    }
}
